package com.yunwushanhe.controller;



import com.yunwushanhe.annotation.SystemLog;
import com.yunwushanhe.bean.req.RoleAddReq;
import com.yunwushanhe.bean.req.RolePageReq;
import com.yunwushanhe.bean.req.RoleStatusUpdateReq;
import com.yunwushanhe.bean.req.RoleUpdateReq;
import com.yunwushanhe.bean.ret.ResponseResult;
import com.yunwushanhe.bean.vo.*;
import com.yunwushanhe.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色信息表(Role)表控制层
 *
 * @author 抬头看看天
 * @since 2023-08-24 10:38:03
 */
@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("/list")
    @SystemLog(businessName = "分页查询所有角色的接口，可以模糊查询")
    public ResponseResult<PageVO<List<RolePageVO>>> listRolePage(RolePageReq rolePageReq){
        return roleService.listRolePage(rolePageReq);
    }

    @PutMapping("/changeStatus")
    @SystemLog(businessName = "简易改变角色状态的接口")
    public ResponseResult<Object> changeRoleStatus(@RequestBody RoleStatusUpdateReq roleStatusUpdateReq){
        return roleService.changeRoleStatus(roleStatusUpdateReq);
    }

    @PostMapping
    @SystemLog(businessName = "增加角色的接口")
    public ResponseResult<Object> addRole(@RequestBody RoleAddReq roleAddReq){
        return roleService.addRole(roleAddReq);
    }

    @GetMapping("/{id}")
    @SystemLog(businessName = "根据id查询所有指定角色信息的接口，用于角色信息修改回显")
    public ResponseResult<RoleUpdateVO> getRoleById(@PathVariable("id") Long id){
        return roleService.getRoleById(id);
    }

    @PutMapping
    @SystemLog(businessName = "修改角色相关信息的接口,特别注意一下与menu的关系是怎么处理的")
    public ResponseResult<Object> updateRoleById(@RequestBody RoleUpdateReq roleUpdateReq){
        return roleService.updateRoleById(roleUpdateReq);
    }

    @DeleteMapping("/{id}")
    @SystemLog(businessName = "删除角色的接口")
    public ResponseResult<Object> deleteRoleById(@PathVariable("id") String id){
        return roleService.deleteRoleById(id);
    }

    @GetMapping("/listAllRole")
    @SystemLog(businessName = "查询角色列表接口，且这些角色状态都是正确的，这个接口主要是与 用户新增接口 或是 根据id查询用户信息回显接口 配合使用。")
    public ResponseResult<List<RoleListVO>> getRoleList(){
        return roleService.getRoleList();
    }
}

